package com.example.sharesinfo.ui;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.sharesinfo.R;
import com.example.sharesinfo.base.BaseApp;
import com.example.sharesinfo.base.BaseUIActivity;
import com.example.sharesinfo.bean.PersonalCenterBean;
import com.example.sharesinfo.entity.Constants;
import com.example.sharesinfo.helper.ActivityHelper;
import com.example.sharesinfo.helper.GlideHelper;
import com.example.sharesinfo.utils.CleanMessageUtil;
import com.example.sharesinfo.utils.LogUtils;
import com.squareup.leakcanary.RefWatcher;

import de.hdodenhof.circleimageview.CircleImageView;

public class MeActivity extends BaseUIActivity implements View.OnClickListener {
    private final static String LogTag = "PersonalCenterActivity:";
    private PersonalCenterBean mUser;
    private ImageButton ib_return;
    private CircleImageView iv_me_photo;
    private TextView tv_nickname;
    private LinearLayout ll_me_info;
    private LinearLayout ll_chat;
    private LinearLayout ll_feedback;
    private LinearLayout ll_about_us;
    private LinearLayout ll_help;
    private LinearLayout ll_setting;

    public static void startActivity(Context mContext, PersonalCenterBean user) {
        Intent intent = new Intent(mContext, MeActivity.class);
        intent.putExtra(Constants.INTENT_USER_BEAN, user);
        mContext.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_me);
        ActivityHelper.getInstance().addActivity(MeActivity.this);
        mUser = (PersonalCenterBean) getIntent().getSerializableExtra(Constants.INTENT_USER_BEAN);
        initView();
        loadInfo();
    }

    private void initView() {
        ib_return = findViewById(R.id.ib_return);
        ib_return.setOnClickListener(this);
        iv_me_photo = findViewById(R.id.iv_me_photo);
        tv_nickname = findViewById(R.id.tv_nickname);
        ll_me_info = findViewById(R.id.ll_me_info);
        ll_me_info.setOnClickListener(this);
        ll_chat = findViewById(R.id.ll_chat);
        ll_chat.setOnClickListener(this);
        ll_feedback = findViewById(R.id.ll_feedback);
        ll_feedback.setOnClickListener(this);
        ll_about_us = findViewById(R.id.ll_about_us);
        ll_about_us.setOnClickListener(this);
        ll_help = findViewById(R.id.ll_help);
        ll_help.setOnClickListener(this);
        ll_setting = findViewById(R.id.ll_setting);
        ll_setting.setOnClickListener(this);
    }

    /**
     * 加载个人信息
     */
    private void loadInfo() {
        GlideHelper.loadUrl(this, mUser.getImageUrl(), iv_me_photo);
        tv_nickname.setText(mUser.getUsername());
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            default:
                break;
            case R.id.ib_return:
                finish();
                break;
            case R.id.ll_me_info:
                PersonalCenterActivity.startActivity(this, mUser, false);
                break;
            case R.id.ll_chat:
                startActivity(new Intent(this, ChatRecordActivity.class));
                break;
            case R.id.ll_feedback:
                startActivity(new Intent(this, FeedBackActivity.class));
                break;
            case R.id.ll_about_us:
                startActivity(new Intent(this, AboutUsActivity.class));
                break;
            case R.id.ll_help:
                break;
            case R.id.ll_setting:
                startActivity(new Intent(this, SettingActivity.class));
                break;
        }
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
//        RefWatcher refWatcher = BaseApp.getRefWatcher(this);//1
//        refWatcher.watch(this);
    }
}
